package com.atom.common.remote.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.activiti.engine.impl.util.json.JSONObject;

import com.atom.common.delegate.DelegateInfo;
import com.atom.common.util.PreConditionUtil;
import com.sinosoft.cnmuseum.utils.Status;

public class UserUtil {
  
  private String userid;
  
  private String username;
  
  private String orgname;  
  
  private String orgid;
  
  private String position;
  
  private DelegateInfo delegateInfo;
    
  public UserUtil() {
    super();
  }
  
  public UserUtil(JSONObject userJSON) {
    PreConditionUtil.checkNotNull(userJSON.getString("orgid"), "orgid is null");
    PreConditionUtil.checkNotNull(userJSON.getString("orgname"), "orgname is null");
    PreConditionUtil.checkNotNull(userJSON.getString("userid"), "userid is null");
    PreConditionUtil.checkNotNull(userJSON.getString("username"), "username is null");
    this.orgid = userJSON.getString("orgid");
    this.orgname = userJSON.getString("orgname");
    this.userid = userJSON.getString("userid");
    this.username = userJSON.getString("username");
    this.setPosition(null);
  }

  public UserUtil(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session != null) {
    	this.userid = (String) session.getAttribute(Status.SESSION_USERID);
    	this.username = (String) session.getAttribute(Status.SESSION_USERNAME);
    }
  }

  public String getUserid() {
    return userid;
  }

  public void setUserid(String userid) {
    this.userid = userid;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getOrgname() {
    return orgname;
  }

  public void setOrgname(String orgname) {
    this.orgname = orgname;
  }

  public String getOrgid() {
    return orgid;
  }

  public void setOrgid(String orgid) {
    this.orgid = orgid;
  }

  public DelegateInfo getDelegateInfo() {
    return delegateInfo;
  }

  public void setDelegateInfo(DelegateInfo delegateInfo) {
    this.delegateInfo = delegateInfo;
  }

  public String getPosition() {
    return position;
  }

  public void setPosition(String position) {
    this.position = position;
  }

}
